import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
import { Base } from "@/entities.base/base.entity";
import { Customer } from "../customer.entity";

@Entity({ comment: '客户积分表', name: 'basis_customer_points' })
export class CustomerPoints extends Base {

    /** 积分批次编号 */
    @Column({
        comment: '积分批次编号',
        length: 50,
        unique: true, // 批次编号唯一
    })
    batchNumber: string;

    /** 积分金额 */
    @Column({
        comment: '积分金额',
        type: 'decimal',
        precision: 10,
        scale: 2,
    })
    pointsAmount: number;

    /** 积分来源类型 */
    @Column({
        comment: '积分来源类型', // 如：充值赠送、生日赠送、活动赠送、手动调整等
        length: 50,
    })
    sourceType: string;

    /** 积分来源说明 */
    @Column({
        comment: '积分来源说明',
        length: 200,
        nullable: true,
    })
    sourceDescription?: string;

    /** 积分有效期开始时间 */
    @Column({
        comment: '积分有效期开始时间',
        type: 'date',
        nullable: true,
    })
    validFrom?: Date;

    /** 积分有效期结束时间 */
    @Column({
        comment: '积分有效期结束时间',
        type: 'date',
        nullable: true,
    })
    validTo?: Date;

    /** 剩余积分 */
    @Column({
        comment: '剩余积分', // 该批次积分的剩余数量
        type: 'decimal',
        precision: 10,
        scale: 2,
        default: 0,
    })
    remainingPoints: number;

    /** 积分状态 */
    @Column({
        comment: '积分状态', // active正常、exhausted已用完、expired已过期
        length: 20,
        default: 'active',
    })
    status: string;

    /** 备注 */
    @Column({
        type: 'text',
        comment: '备注',
        nullable: true,
    })
    remark?: string;

    /** 关联的客户ID */
    @Column({
        comment: '客户ID',
        nullable: false,
    })
    customerId: string;

    /** 关联客户 - 多对一关系 */
    @ManyToOne(() => Customer, { onDelete: 'CASCADE' })
    @JoinColumn({ name: 'customerId' })
    customer: Customer;
} 